// pages/certificate/certificate.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screenHeight: app.globalData.screenHeight,
    currentIndex: -1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    app.globalData.wxRequest.requestGet('certificate/getList.do', {}).then(res => {
      // console.log(res);
      if (res.code == '201') {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
        return
      }
      that.setData({
        certificate: res.data,
      })
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: '请求失败',
        icon: 'error'
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  clickShowHide(e) {
    let that = this;
    // console.log(e);
    let index = e.currentTarget.dataset.index;
    let currentIndex = that.data.currentIndex;
    if (currentIndex == -1) {
      currentIndex = index
    } else if (currentIndex != -1 && currentIndex != index) {
      currentIndex = index
    } else if (currentIndex != -1 && currentIndex == index) {
      currentIndex = -1
    }
    that.setData({
      currentIndex: currentIndex
    })
  },
  acaddemy(e) {
    let id = e.currentTarget.id;
    wx.navigateTo({
      url: '/pages/academy/academy?certificateId=' + id,
    })
  }
})